from time import sleep

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

from base.base_page import BasePage


class LoginPage(BasePage):

    def __init__(self):
        super().__init__('mp')

        self.ele_phone = By.XPATH, '//input[@placeholder = "请输入手机号"]'

        self.ele_code = By.XPATH, '//*[@placeholder = "验证码"]'

        self.ele_login = By.XPATH, '//*[contains(text(),"登录")]'

    def login_page(self, phone_val, code_val):

        sleep(1)
        phone = self.find_ele(self.ele_phone)
        ActionChains(self.driver).double_click(phone).perform()
        phone.send_keys(Keys.DELETE)
        phone.send_keys(phone_val)

        code = self.find_ele(self.ele_code)
        ActionChains(self.driver).double_click(code).perform()
        code.send_keys(Keys.DELETE)
        code.send_keys(code_val)

        # 点击登录
        self.click_element(self.find_ele(self.ele_login))

if __name__ == '__main__':
    LoginPage().login_page()
